home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v16n10 / embedcp.exe / CODE.EXE / TDRPROC.C < prev   
Encoding:
C/C++ Source or Header  |  1991-05-28  |  7.5 KB  |  223 lines

  1. // MIOTDREM - Command processor
  2. // ----------------------------
  3. //
  4. // Copyright (c) 1991, Stuart G. Phillips.  All rights reserved.
  5. //
  6. // Permission is granted for non-commercial use of this software.
  7. // You are expressly prohibited from selling this software in any form,
  8. // distributing it with another product, or removing this notice.
  9. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  10. // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  11. // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. // PURPOSE.
  13. //
  14. // This module contains the command processor for the MIO version of
  15. // TDREMOTE.  The procedure tdr_processor() acts as a dispatcher for
  16. // incoming commands.  Actual execution of each command is handled in
  17. // other modules (grouped by function type).  tdr_processor() responds
  18. // with appropriate response to incoming commands that are not fully
  19. // supported in the MIO environment (e.g. Requests for file access etc).
  20. //
  21. //
  22.  
  23.  
  24. #include "miotdr.h"
  25.  
  26.  
  27. // Globals
  28.  
  29. struct td_imsg *msgq = (struct td_imsg *) NULL;
  30.  
  31.  
  32. void tdr_processor()
  33. {
  34.     struct td_omsg *txb = (struct td_omsg *) tx_buffer;
  35.     unsigned int status;
  36.  
  37.     while (1){
  38.         if (msgq == (struct td_imsg *) NULL) continue;
  39.  
  40.         switch (msgq->cmd){
  41.             case TD_SYNC:   // Initial greeting - say Hello !
  42.  
  43.                 txb->td_sync.code = TD_SYNC;
  44.                 txb->td_sync.cpu = TD_80186;
  45.                 txb->td_sync.i8087 = NO_8087;
  46.                 txb->td_sync.version = TD_VERSION;
  47.  
  48.                 send((unsigned char *)txb, sizeof(txb->td_sync));
  49.                 break;
  50.  
  51.             case TD_SENDFILE: // Unsupported - receive file from host
  52.  
  53.                 txb->td_sendfile.status = FALSE;
  54.                 send((unsigned char *)txb, sizeof(txb->td_sendfile));
  55.                 break;
  56.  
  57.             case TD_GETFINFO: // Get file information
  58.  
  59.                 txb->td_getfinfo.filetime = *((long *)0xfc);
  60.                 send((unsigned char *)txb, sizeof(txb->td_getfinfo));
  61.                 break;
  62.  
  63.             case TD_GO: // Execute the program
  64.  
  65.                 status = go_program();
  66.                 if (status != TD_SSTOP){
  67.                     txb->td_stopped.state = (unsigned char) status;
  68.                     txb->td_stopped.term_code = 0;
  69.                     txb->td_stopped.i8087 = NO_8087;
  70.                     send((unsigned char *)txb, sizeof(txb->td_stopped));
  71.                 }
  72.                 break;
  73.  
  74.             case TD_STOP: // Stop execution
  75.                 // Already processed and acknowledged
  76.                 break;
  77.  
  78.             case TD_READMEM: // Read memory
  79.  
  80.                 read_memory(msgq->data.td_readmem.segment,
  81.                             msgq->data.td_readmem.offset,
  82.                             msgq->data.td_readmem.count);
  83.                 break;
  84.  
  85.             case TD_WRITEMEM: // Write memory
  86.  
  87.                 write_memory(msgq->data.td_writemem.segment,
  88.                              msgq->data.td_writemem.offset,
  89.                              msgq->data.td_writemem.count,
  90.                              msgq->data.td_writemem.data);
  91.                 break;
  92.  
  93.             case TD_READIO: // Read IO port
  94.  
  95.                 read_io(msgq->data.td_readio.port,
  96.                         msgq->data.td_readio.word_or_byte);
  97.                 break;
  98.  
  99.             case TD_WRITEIO: // Write IO port
  100.  
  101.                 write_io(msgq->data.td_writeio.port,
  102.                          msgq->data.td_writeio.word_or_byte,
  103.                          msgq->data.td_writeio.value);
  104.                 break;
  105.  
  106.             case TD_READREGS: // Read processor registers
  107.  
  108.                 read_regs();
  109.                 break;
  110.  
  111.             case TD_WRITEREGS: // Write processor registers
  112.  
  113.                 write_regs(&msgq->data.td_write_regs.regs);
  114.                 break;
  115.  
  116.             case TD_READFP:  // Read floting point status
  117.             case TD_WRITEFP: // Write floating point status
  118.                 // Since we told the host end there was no numeric
  119.                 // coprocessor, it shouldn't read or write the status...
  120.                 // ...right ?
  121.  
  122.                 send_ack();
  123.                 break;
  124.  
  125.             case TD_LOADPROG: // Load program into remote memory
  126.  
  127.                 // We presume that the program has already been loaded
  128.                 // using MIOLOAD and that it is loaded at 0000:0100
  129.                 // on up.  So we tell a white lie and tell the host
  130.                 // end that this operation was successful.
  131.  
  132.                 txb->td_loadprog.status = 0;
  133.                 txb->td_loadprog.pid = 0;
  134.                 txb->td_loadprog.i8087 = FALSE;
  135.  
  136.                 // Nuke the timestamp at 0000:00FC so that any attempts
  137.                 // to restart the program are guaranteed NOT to work.
  138.  
  139.                 *((long *)0xfc) = 0;
  140.  
  141.                 send((unsigned char *)txb, sizeof(txb->td_loadprog));
  142.                 break;
  143.  
  144.             case TD_MAKEPSP: // Make a PSP
  145.  
  146.                 // Since we're not running DOS on MIO, there is no
  147.                 // concept of a PSP.  We also assume that the MIO
  148.                 // start up routine takes care of assumptions about the
  149.                 // machine environment such as stack, data segment etc.
  150.                 // We ignore this command completely.
  151.  
  152.                 send_ack();
  153.                 break;
  154.  
  155.             case TD_PROGFREE: // Free program memory
  156.  
  157.                 // Another DOS related concept with no MIO analogy.
  158.                 // We also ignore this command !
  159.  
  160.                 send_ack();
  161.                 break;
  162.  
  163.             case TD_MEMSET: // Set a block of memory
  164.  
  165.                 set_mem(msgq->data.td_memset.segment,
  166.                         msgq->data.td_memset.offset,
  167.                         msgq->data.td_memset.count,
  168.                         msgq->data.td_memset.value);
  169.                 break;
  170.  
  171.             case TD_MEMCPY: // Copy a block of memory
  172.  
  173.                 copy_mem(msgq->data.td_memcopy.src_segment,
  174.                          msgq->data.td_memcopy.src_offset,
  175.                          msgq->data.td_memcopy.dst_segment,
  176.                          msgq->data.td_memcopy.dst_offset,
  177.                          msgq->data.td_memcopy.count);
  178.                 break;
  179.  
  180.             case TD_GETPINFO: // Get program information
  181.  
  182.                 txb->td_getpinfo.mem_dos = 0;
  183.                 txb->td_getpinfo.mem_debugger = 0;
  184.                 txb->td_getpinfo.mem_symbols = 0;
  185.                 txb->td_getpinfo.mem_program = 0;
  186.                 txb->td_getpinfo.mem_available = 0;
  187.                 txb->td_getpinfo.ems_dos = 0;
  188.                 txb->td_getpinfo.ems_debugger = 0;
  189.                 txb->td_getpinfo.ems_program = 0;
  190.                 txb->td_getpinfo.ems_available = 0;
  191.                 txb->td_getpinfo.dos_version = 0;
  192.                 txb->td_getpinfo.hardware_bkpts = 0;
  193.                 txb->td_getpinfo.ems_present = 0;
  194.                 for (int i = 0; i < VECCOUNT; i++)
  195.                     txb->td_getpinfo.intflags[i] = 0;
  196.  
  197.                 send((unsigned char *)txb,sizeof(txb->td_getpinfo));
  198.                 break;
  199.  
  200.             case TD_OVLHOOK: // Set PASCAL overlay hook
  201.  
  202.                 // Not supported - just say we did it and carry on
  203.  
  204.                 send_ack();
  205.                 break;
  206.  
  207.             case TD_BYE: // Remote has signalled end of session
  208.  
  209.                 send_ack();
  210.                 break;
  211.  
  212.             default: // Oh what to do ?!
  213.  
  214.                 send_ack();
  215.                 break;
  216.         }
  217.  
  218.         msgq = (struct td_imsg *) NULL;
  219.     }
  220. }
  221.  
  222.  
  223.